<?php
class SitemapController extends Apps_Controller_Action_Default {
	public function preDispatch() {
		$layout = new Zend_Layout();
		$layout->banner = 'banner';
	}

	public function indexAction() {
	    $tourCateModel     = new M_TourCategory();
        $tourModel         = new M_Tour();
        $cruiseCateModel   = new M_CruiseCategory();
        $cruiseModel       = new M_Cruise();
        $tourStyle         = new M_TourStyle();
        $countryModel      = new M_Country();
        $regionModel       = new M_Region();
        $tbEvent = new M_DbTable_Event();

        $tbCruise		   = new M_DbTable_Cruise();
        // GROUP
		    //tour
		    $listTourCate = $tourCateModel->listCategoryShowHome()->query()->fetchAll();
		    //list cruise
	        $listCruiseCate = $cruiseCateModel->listCategoryShowHome()->query()->fetchAll();
	        //Trip in style : get trip style of Vietnam ; counttry_id = 1
	        $listTourStyle = $tourStyle->listStyleShowHome()->query()->fetchAll();

	   // COUNTRY
	        //Hotel and resort: by location, coutry
	        $listCountry = $countryModel->listCountry()->query()->fetchAll();
	        if($listCountry) {
	            foreach($listCountry as $k => $v) {
	                $listCountry[$k]['list_region'] = $regionModel->listRegionByCountryId($v['id'])->query()->fetchAll();
	            }
	        }

	    // DETAIL
	    	//tour
	    	$listTour = $tourModel->getListActive()->query()->fetchAll();
	    	
	    	//CRUISE
	    	$cruiseItineraryTourModel = new M_CruiseItineraryTour();
	    	$listCruise = $cruiseModel->getListActive()->query()->fetchAll();
	    	
	    	$categoryId = $listCruiseCate[0]['id'];
	    	
	    	$cruiseItineraryTourModel = new M_CruiseItineraryTour();
	    	$this->view->listCruise = $cruiseItineraryTourModel->listCruiseTourByType($categoryId)->query()->fetchAll();
	    	$this->view->cruiseCategory = $listCruiseCate[0]['cruise_category_title'];
	    	
	    	//Zend_Debug::dump($listParentCruise);die();
        //MICE
	   	$listMiceGeneral = $tbEvent->listMice($tbEvent::TYPE_GENERAL)->query()->fetchAll();
        $listMiceIncentve = $tbEvent->listMice($tbEvent::TYPE_INCENTIVE)->query()->fetchAll();
        $listMiceMeeting = $tbEvent->listMice($tbEvent::TYPE_MEETING_CONFERENCE)->query()->fetchAll();
        $listMiceEvent = $tbEvent->listMice($tbEvent::TYPE_EVENT)->query()->fetchAll();

        $this->view->listMiceGeneral = $listMiceGeneral;
        $this->view->listMiceIncentve= $listMiceIncentve;
        $this->view->listComingEvent = $listMiceEvent;
        $this->view->listMiceMeeting = $listMiceMeeting;

        $this->view->listCountry     = $listCountry;
        $this->view->listTourStyle   = $listTourStyle;
        $this->view->listTourCate    = $listTourCate;
        $this->view->listCruiseCate  = $listCruiseCate;
        $this->view->listTour		 = $listTour;
	}
	
	public function getCruiseMap($categoryId) {
		if(!$categoryId) {
			return null;
		}
		$cruiseModel     	 = new M_Cruise();
		$cruiseTypeModel 	 = new M_CruiseType();
		$cruiseItineraryTourModel = new M_CruiseItineraryTour();
	
		$cruiseType = $cruiseTypeModel->getList()->query()->fetchAll();
		if($cruiseType) {
			foreach($cruiseType as $k => $v) {
				$listParentCruise = $cruiseModel->listCruiseMenuLeft($categoryId, $v['id'])->query()->fetchAll();
				foreach($listParentCruise as $key => $value) {
					$listCruise = $cruiseModel->listCruiseMenuLeft($categoryId, $v['id'], $value['id'])->query()->fetchAll();
	
					if($listCruise) {
						foreach($listCruise as $cK => $cruise) {
							$cruiseItineraryTour = $cruiseItineraryTourModel->getCruiseItineraryTourByCruiseId($cruise['id'])->query()->fetch();
							if($cruiseItineraryTour) {
								$listCruise[$cK]['link_id']    = $cruiseItineraryTour['id'];
								$listCruise[$cK]['link_title'] = $cruiseItineraryTour['title'];
							} else {
								$listCruise[$cK]['link_id']    = -1;
								$listCruise[$cK]['link_title'] = $cruise['name'];
							}
						}
						$listParentCruise[$key]['link_id']    = -1;
						$listParentCruise[$key]['link_title'] = $cruise['name'];
						$listParentCruise[$key]['list_child_cruise'] = $listCruise;
					} else {
						$listParentCruise[$key]['link_id']    = -1;
						$listParentCruise[$key]['link_title'] = $cruise['name'];
					}
				}
				$cruiseType[$k]['list_cruise'] = $listParentCruise;
			}
			return $cruiseType;
		}
		return null;
	}
	
}